package wsz.springboot.server;

import org.apache.catalina.startup.Tomcat;
import org.springframework.stereotype.Component;

/**
 * tomcat管控
 * @author wsz
 * @date 2021/11/8 16:11
 **/
@Component
public class TomcatFactory implements WebServerFactory {
    private int port = 8080;

    @Override
    public void createWebServer() {
        try {
            Tomcat tomcat = new Tomcat();
            tomcat.setPort(port);
            tomcat.addWebapp("/", System.getProperty("user.dir"));
            tomcat.start();
            tomcat.getServer().await();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
